package com.rttmall.shopbackend.app.gambling.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rttmall.shopbackend.app.gambling.mapper.GamblingPeriodCustomMapper;
import com.rttmall.shopbackend.app.gambling.pojo.GamblingPeriodCustom;
import com.rttmall.shopbackend.app.gambling.service.GamblingPeriodService;

@Service
public class GamblingPeriodServiceImpl implements GamblingPeriodService {

	@Autowired
	private GamblingPeriodCustomMapper gamblingPeriodCustomMapper;
	
	@Override
	public Map queryGamblingPeriod(GamblingPeriodCustom gamblingPeriodCustom) {
		Map map = new HashMap();
        List<GamblingPeriodCustom> gamblingPeriodCustomList = gamblingPeriodCustomMapper.queryGamblingPeriod(gamblingPeriodCustom);
        gamblingPeriodCustomList.forEach(w->{
        	String endString = "";
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        	Date createDate = new Date(w.getCreateTime());
        	if(w.getCompleteTime()!=null){
            	Date endDate = new Date(w.getCompleteTime());
            	endString = sdf.format(endDate);
        	}
    		w.setStartAndEndTime(sdf.format(createDate)+"/"+endString);
    		w.setSumAndRemainCount(w.getTotalCount()+"/"+w.getRemainingCount());
        });
        int sum = gamblingPeriodCustomMapper.queryGamblingPeriodCount(gamblingPeriodCustom);
        map.put("data", gamblingPeriodCustomList);
        map.put("total", sum);
        return map;
	}

}
